<!DOCTYPE html>
<html lang="en" >
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="author" content="GoJun" />
	
	
	
	<title>使用 Python3 爬取 Play 商店后台评论笔记记录 ｜ GoJun</title>
	
    
    
    <meta name="description" content="Python selenium 三种等待方式 学习链接：https://huilansame.github.io/huilansame.github.io/archivers/sleep-implicitlywait-wait 项目" />
    

    
    
    <meta name="keywords" content="Hugo, theme, zozo" />
    

	
    
    <link rel="shortcut icon" href="https://gojun.me/images/favicon.ico" />

    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.mecss/normalize.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.0/animate.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.me/css/zozo.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/remixicon@2.5.0/fonts/remixicon.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.me/css/highlight.css" />

    
    
</head>

<body>
    <div class="main animate__animated animate__fadeInDown">
        <div class="nav_container animated fadeInDown">
    <div class="site_nav" id="site_nav">
        <ul>
            
            <li>
                <a href="/">Home</a>
            </li>
            
            <li>
                <a href="/posts/">Archive</a>
            </li>
            
            <li>
                <a href="/tags/">Tags</a>
            </li>
            
            <li>
                <a href="/projects/">Projects</a>
            </li>
            
        </ul>
    </div>
    <div class="menu_icon">
        <a id="menu_icon"><i class="ri-menu-line"></i></a>
    </div>
</div>
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <h1>
                <a href="https://gojun.me">
                    <span>GoJun</span>
                </a>
            </h1>
        </div>
        <div class="description">
            <p class="sub_title">为向往生活努力奋斗！</p>
            <div class="my_socials">
                
                
                <a href="https://github.com/freelander" title="github" target="_blank"><i class="ri-github-fill"></i></a>
                
                
                <a href="https://gojun.me/index.xml" type="application/rss+xml" title="rss" target="_blank"><i
                        class="ri-rss-fill"></i></a>
            </div>
        </div>
    </div>
</div>
        <div class="content">
            <div class="post_page">
                <div class="post animate__animated animate__fadeInDown">
                    <div class="post_title post_detail_title">
                        <h2><a href='/posts/python-learn/'>使用 Python3 爬取 Play 商店后台评论笔记记录</a></h2>
                        <span class="date">2018.03.13</span>
                    </div>
                    <div class="post_content markdown"><h3 id="python-selenium-三种等待方式">Python selenium 三种等待方式</h3>
<p>学习链接：https://huilansame.github.io/huilansame.github.io/archivers/sleep-implicitlywait-wait</p>
<p>项目使用以下方式</p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback"># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()
driver.implicitly_wait(10)  # 隐性等待和显性等待可以同时用，但要注意：等待的最长时间取两者之中的大者
driver.get(&#39;https://huilansame.github.io&#39;)
locator = (By.LINK_TEXT, &#39;CSDN&#39;)

try:
    WebDriverWait(driver, 20, 0.5).until(EC.presence_of_element_located(locator))
    print driver.find_element_by_link_text(&#39;CSDN&#39;).get_attribute(&#39;href&#39;)
finally:
    driver.close()
    
</code></pre></div><h3 id="python-遍历-list">Python 遍历 list</h3>
<p>学习链接：https://blog.csdn.net/baidu_24545901/article/details/78729309</p>
<p>采用的方式：</p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">temp = [{&#39;h&#39;: &#39;u&#39;}, {&#39;h&#39;: &#39;a&#39;}, {&#39;h&#39;: &#39;u&#39;}]
    for i, val in enumerate(temp):
        print(val[&#39;h&#39;])
</code></pre></div><h3 id="python3-词典数组操作">Python3 词典数组操作</h3>
<p>学习链接：https://blog.csdn.net/dance117/article/details/80304238</p>
<p><strong>定义一个空的词典数组</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">review_data = {}
</code></pre></div><p><strong>增加</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">review_data[&#39;review_content&#39;] = &#39;very good&#39;
review_data[&#39;review_rating&#39;] = 5

print(review_data)

{&#39;review_content&#39;:&#39;very good&#39;, &#39;review_rating&#39;: 5}
</code></pre></div><p><strong>删除</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">review_data[&#39;review_content&#39;] = &#39;very good&#39;
# 指定删除
del review_data[&#39;review_content&#39;]
# 全部删除
review_data.clear()
# 删除指定 key，且返回删除的key的值
review_data.pop(&#39;review_content&#39;)
</code></pre></div><p><strong>修改</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback"># 给指定的key重新赋值修改
review_data[&#39;name&#39;] = &#39;jun&#39;

# 使用 update() 方法
# 无重复key，相当于新插入
review_data = {&#39;name&#39;: &#39;jun&#39;}
review_data.update({&#39;rating&#39;: 5})
print(review_data)  ----&gt;   {&#39;name&#39;: &#39;jun&#39;, &#39;rating&#39;: 5}

# 重复key，会覆盖旧的值
review_data = {&#39;name&#39;: &#39;jun&#39;}
review_data.update({&#39;name&#39;: &#39;jun&#39;})

print(review_data)  ----&gt;   {&#39;name&#39;: &#39;jun&#39;}
</code></pre></div><p><strong>查询</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">review_data = {&#39;name&#39;: &#39;jun&#39;}
reivew_data[&#39;name&#39;]
</code></pre></div><p><strong>两个字典合并</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">dic1 = {&#39;name&#39;: &#39;jun&#39;}
dic2 = {&#39;age&#39;: &#39;18&#39;}

dic1.update(dic2)
print(dic1)  ----&gt; {&#39;name&#39;: &#39;jun&#39;, &#39;age&#39;: &#39;18&#39;}
</code></pre></div><h3 id="表格处理">表格处理</h3>
<p>官方文档：https://docs.python.org/3/library/csv.html<br>
参考链接：https://python3-cookbook.readthedocs.io/zh_CN/latest/c06/p01_read_write_csv_data.html</p>
<p><strong>读取表格数据</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">with open(&#39;/Users/apple/Desktop/review.csv&#39;, newline=&#39;&#39;) as c:
    reader = csv.reader(c)
    for r in reader:
        print(r)
</code></pre></div><p><strong>写入数据</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback"># encoding=&#39;utf-8-sig&#39; 防止写入中文乱码
with open(&#39;/Users/apple/Desktop/review.csv&#39;, &#39;w&#39;, newline=&#39;&#39;, encoding=&#39;utf-8-sig&#39;) as c:
    headers = [&#39;Symbol&#39;, &#39;Price&#39;, &#39;Date&#39;, &#39;Time&#39;, &#39;Change&#39;, &#39;Volume&#39;]
    rows = [{&#39;Symbol&#39;: &#39;AA&#39;, &#39;Price&#39;: 39.48, &#39;Date&#39;: &#39;6/11/2007&#39;,
             &#39;Time&#39;: &#39;9:36am&#39;, &#39;Change&#39;: -0.18, &#39;Volume&#39;: 181800},
            {&#39;Symbol&#39;: &#39;AIG&#39;, &#39;Price&#39;: 71.38, &#39;Date&#39;: &#39;6/11/2007&#39;,
             &#39;Time&#39;: &#39;9:36am&#39;, &#39;Change&#39;: -0.15, &#39;Volume&#39;: 195500},
            {&#39;Symbol&#39;: &#39;AXP&#39;, &#39;Price&#39;: 62.58, &#39;Date&#39;: &#39;6/11/2007&#39;,
             &#39;Time&#39;: &#39;9:36am&#39;, &#39;Change&#39;: -0.46, &#39;Volume&#39;: 935000},
            ]
    c_w = csv.DictWriter(c, headers)
    c_w.writeheader()
    c_w.writerows(rows)
</code></pre></div></div>
                    <div class="post_footer">
                        
                        <div class="meta">
                            <div class="info">
                                <span class="field tags">
                                    <i class="ri-stack-line"></i>
                                    
                                    <a href="https://gojun.me/tags/python/">Python</a>
                                    
                                    <a href="https://gojun.me/tags/%E7%88%AC%E8%99%AB/">爬虫</a>
                                    
                                </span>
                            </div>
                        </div>
                        
                    </div>
                </div>
                
                
                <div class="doc_comments"></div>
                
            </div>
        </div>
    </div>
    <a id="back_to_top" href="#" class="back_to_top"><i class="ri-arrow-up-s-line"></i></a>
    <footer class="footer">
    <div class="footer_slogan">
        <span></span>
    </div>
</footer>
    <script src="https://gojun.me/js/jquery-3.5.1.min.js"></script>
<link href="https://gojun.me/css/fancybox.min.css" rel="stylesheet">
<script src="https://gojun.me/js/fancybox.min.js"></script>
<script src="https://gojun.me/js/zozo.js"></script>


<script type="text/javascript" async
    src="https://cdn.bootcss.com/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
        MathJax.Hub.Config({
            tex2jax: {
                inlineMath: [['$', '$'], ['\\(', '\\)']],
                displayMath: [['$$', '$$'], ['\[\[', '\]\]']],
                processEscapes: true,
                processEnvironments: true,
                skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
                TeX: {
                    equationNumbers: { autoNumber: "AMS" },
                    extensions: ["AMSmath.js", "AMSsymbols.js"]
                }
            }
        });

        MathJax.Hub.Queue(function () {
            
            
            
            var all = MathJax.Hub.getAllJax(), i;
            for (i = 0; i < all.length; i += 1) {
                all[i].SourceElement().parentNode.className += ' has-jax';
            }
        });
    </script>

<style>
    code.has-jax {
        font: inherit;
        font-size: 100%;
        background: inherit;
        border: inherit;
        color: #515151;
    }
</style>



<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'UA-142037913-1', 'auto');
	
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>

</body>

</html>